﻿namespace DesignPatterns.SingletonPattrens
{
    /// <summary>
    /// 双重锁单例模式，绝大多数情况下，能保证唯一性，线程安全
    /// </summary>
    public class DoublelockSingleton
    {
        private static DoublelockSingleton instance;
        private static readonly object locker = new object();
        private DoublelockSingleton() { }
        public static DoublelockSingleton getInstance()
        {
            if (instance == null)
            {
                lock (locker)
                {
                    if (instance == null)
                    {
                        instance = new DoublelockSingleton();
                    }
                }
            }
            return instance;
        }
    }
}
